package com.ynwt.service;

import com.ynwt.domain.User;
import com.ynwt.constant.JmsDestinationName;
import com.ynwt.jms.QueueClient;
import com.ynwt.model.BaseRequest;
import com.ynwt.model.sign.SignResponse;
import com.ynwt.repository.UserDao;
import com.ynwt.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;

/**
 * Created by huangying on 2017/6/8.
 */
@Service
public class SignServiceImpl implements SignService {

    /**
     * 签到
     * 发送jms到签到系统进行签到
     *
     * @param user
     * @return
     */
    @Override
    public SignResponse sign(User user) {

        BaseRequest request = new BaseRequest(user.getUnionid());

        SignResponse response = null;
        //向签到系统发送签到信息
        try {
            response = JsonUtil.toBean(client.sendAndReceive(request.toString(), JmsDestinationName.SIGN, 10000), SignResponse.class);
        } catch (JMSException e) {
            e.printStackTrace();
        }

        return response;
    }

    @Autowired
    private UserDao userDao;

    @Autowired
    private QueueClient client;

}
